package com.mmy.dao.visa;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.mmy.domain.visa.TVisaStuff;

/**
 * 类的介绍：dao层 签证所需材料信息
 *
 * @author hanxl
 * @date 2020-07-23
 * @version 1.0
 */

public interface TVisaStuffRepository extends JpaRepository<TVisaStuff, Integer>, JpaSpecificationExecutor<TVisaStuff> {
	/* 获得最大材料编码 */
	@Query(value = "select MAX(iStuffID) from tVisaStuff", nativeQuery = true)
	Object getMaxStuffID();

//创建
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tVisaStuff(iStuffID, iVisaID, iNo, cStuffName, iNumber, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (?1, 0, 0, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);", nativeQuery = true)
	void save(int stuffID);

	/* 查询该签证的材料表 升序排列 */
	@Query(value = "select * from tVisaStuff where iVisaID=?1 ORDER by iNo ASC", nativeQuery = true)
	List<TVisaStuff> findByVisaID(int iVisaID);

	/* 删除该VisaID签证行程 */
	@Transactional
	@Modifying
	@Query(value = "delete from tVisaStuff where iVisaID =?1", nativeQuery = true)
	void deleteByVisaID(int VisaID);

}
